/**
 * @Author: Your name
 * @Date:   2023-02-13 15:27:22
 * @Last Modified by:   Your name
 * @Last Modified time: 2023-02-27 19:03:12
 */
const express = require("express");
const {default:fetch} = require("node-fetch-cjs");
const encryption = require("../utils/encryption");

const wxMenuRouter = express.Router();

wxMenuRouter.post("/create",(req,res,next)=>{
    console.log("createMenu");
    console.log(JSON.stringify(req.body));
    let theUrl = req.body.url;
    let method = req.body.method;
    let params = req.body.params;
    let options = {method}
    if(method === "POST" || method === "PUT"){
        options.body = params;
    }
    fetch(theUrl,options).then(returnValue=>returnValue.json())
    .then((returnValue)=>{
        res.json({"result":JSON.stringify(returnValue||{})});
    }).catch((err)=>{
        console.error(err);
    }).finally(()=>{
        res.end();
    })
})

module.exports = wxMenuRouter
